package JZ24_二叉树中和为某一值的路径;

import java.util.ArrayList;
class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
    this.val = val;

    }
}
public class Solution {
    private ArrayList<ArrayList<Integer>> resultList = new ArrayList<ArrayList<Integer>>();
    private ArrayList<Integer> list = new ArrayList<>();
    public ArrayList<ArrayList<Integer>> FindPath(TreeNode root,int target) {
        if (root == null){
            return resultList;
        }
        list.add(root.val);
        target -= root.val;

        if (target == 0 && root.left == null && root.right == null){
            resultList.add(new ArrayList<Integer>(list));
        }

        FindPath(root.left, target);
        FindPath(root.right, target);
        list.remove(list.size() - 1);
        return resultList;

    }


}